﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EBQ_ROP_SDK_NET.rop
{
    class UploadFile
    {
        public string fileName { get; set; }

        public string fileType { get; set; }

        public byte[] content { get; set; }

        public UploadFile(String filePath)
        {
            this.fileName = Path.GetFileName(filePath);
            this.fileType = Path.GetExtension(filePath);
            FileInfo fi = new FileInfo(filePath);
            long len = fi.Length;
            FileStream fs = new FileStream(filePath, FileMode.Open);
            this.content = new byte[len];
            fs.Read(this.content, 0, (int)len);
            fs.Close();
        }

        public string ToRopString()
        {
            string target = Convert.ToBase64String(Encoding.UTF8.GetBytes(this.fileName)).Replace("=", "").Replace("+", "-").Replace("/", "_");
            target += "@";
            target += Convert.ToBase64String(this.content).Replace("=", "").Replace("+", "-").Replace("/", "_");
            return target;
        }

    }
}
